package com.ming.MathTest;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Auther: tangC
 * @Date: 2020/7/10 15:45
 * @Description:
 */
public class DemoTest {

    private static ReentrantLock lock = new ReentrantLock();
    private static Condition condition = lock.newCondition();
    public static void main(String[] args) {
        BigDecimal bigDecimal =new BigDecimal(54);
        BigDecimal bigDecimal2 =new BigDecimal(54.00);
        bigDecimal.compareTo(bigDecimal2);

        try {

        }catch (Exception e){
            condition.signal();
        }finally {
            lock.unlock();
        }

        Stack<Integer> stackA = new Stack<Integer>();
        Integer i=10;
        while (i>0){
            stackA.push(i--);
        }
        Stack<Integer> stackB = new Stack<Integer>();
        Stack<Integer> stackc = new Stack<Integer>();
        List<Stack<Integer>> list = new ArrayList<>();
        list.add(stackA);
        list.add(stackB);
        list.add(stackc);
        Iterator<Stack<Integer>> iterator = list.iterator();
        System.out.println("startA:"+stackA);
        System.out.println("start:"+new SimpleDateFormat("hh:mm:ss").format(new Date()));
        while (true){
            double indexA = Math.random() * 3;
            double indexB = Math.random() * 3;
            move(list.get((int)indexA),list.get((int)indexB));
            if (stackc.size() == 10){
                if (stackc.peek() ==1){
                    break;
                }
            }
        }
        System.out.println("end:"+new SimpleDateFormat("hh:mm:ss").format(new Date()));
        System.out.println("startC"+stackc);
    }

    public static boolean move(Stack<Integer> stackA,Stack<Integer> stackB){
        if (stackA.empty()){
            return false;
        }
        Integer peekA = stackA.peek();
        if (stackB.isEmpty()){

        }else {
            Integer peekB = stackB.peek();
            if (peekA>peekB){
                return false;
            }
        }

        stackB.push(stackA.pop());
        return true;
    }
}
